/*******************************************************************************
 * Copyright (c) 2007 University of Oslo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University of Oslo - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.diagram.sequence.sedi.model.command;

import org.eclipse.gef.commands.Command;

/**
 * A command that just delegates to another command. It is sometimes useful as a
 * placeholder for the real command, that for various reasons are not known
 * exactly that the time.
 * 
 * @author frankd@ifi.uio.no
 */
public class DelegatingCommand extends Command {
	private Command command;

	public DelegatingCommand() {
	}

	public DelegatingCommand(final Command command) {
		this.command = command;
	}

	public void setCommand(Command command) {
		this.command = command;
	}

	public void execute() {
		if (command != null)
			command.execute();
	}

	public void undo() {
		if (command != null)
			command.undo();
	}

	@Override
	public void redo() {
		if (command != null) {
			command.redo();
		}
	}

	public void dispose() {
		if (command != null) {
			command.dispose();
			command = null;
		}
	}
}
